#include "App.h"
#include "MessageCodes.h"
#include "LoggerImpl.h"
Logger logger;

App::App(int argc, char *argv[]) 
: QApplication(argc, argv, true)
{
    logger.setPath(QCoreApplication::applicationDirPath());
    logger.addn("== dbs started ==");
    _mainModule.reset(new MainModule);
}

int App::Run()
{
    _mainModule->Execute();
    return QApplication::exec();
}

bool App::winEventFilter(MSG* msg, long* result)
{
    bool processed = false;

    if (msg->message == WM_COPYDATA)
    {
        PCOPYDATASTRUCT pCps = reinterpret_cast<PCOPYDATASTRUCT>(msg->lParam);
        VidarCopyStruct vcds = *(VidarCopyStruct*)pCps->lpData;

        switch (vcds.Cmd())
        {
            case MESSAGE_GET_ID:
                {
                    _mainModule->NotifyWorker(vcds.Data1());
                    processed = true;
                    break;
                };
            case MESSAGE_PARENT_HWND:
                {
                    _mainModule->SetParent((HWND)msg->wParam);
                    processed = true;
                    break;
                };
            default:
                processed = false;
        }
    }

    return processed;
}